﻿@model VendorAttributeModel
@if (Model.Id > 0)
{
    <div class="panel-body">
        @await Html.PartialAsync("Table", new DataTablesModel
        {
            Name = "vendorattributevalues-grid",
            UrlRead = new DataUrl("ValueList", "VendorAttribute", new RouteValueDictionary { [nameof(Model.VendorAttributeValueSearchModel.VendorAttributeId)] = Model.VendorAttributeValueSearchModel.VendorAttributeId }),
            UrlDelete = new DataUrl("ValueDelete", "VendorAttribute", null),
            Length = Model.VendorAttributeValueSearchModel.PageSize,
            LengthMenu = Model.VendorAttributeValueSearchModel.AvailablePageSizes,
            ColumnCollection = new List<ColumnProperty>
            {
                new ColumnProperty(nameof(VendorAttributeValueModel.Name))
                {
                    Title = T("Admin.Vendors.VendorAttributes.Values.Fields.Name").Text
                },
                new ColumnProperty(nameof(VendorAttributeValueModel.IsPreSelected))
                {
                    Title = T("Admin.Vendors.VendorAttributes.Values.Fields.IsPreSelected").Text,
                    Width = "100",
                    ClassName = NopColumnClassDefaults.CenterAll,
                    Render = new RenderBoolean()
                },
                new ColumnProperty(nameof(VendorAttributeValueModel.DisplayOrder))
                {
                    Title = T("Admin.Vendors.VendorAttributes.Values.Fields.DisplayOrder").Text,
                    Width = "100",
                    ClassName =  NopColumnClassDefaults.CenterAll
                },
                new ColumnProperty(nameof(VendorAttributeValueModel.Id))
                {
                    Title = T("Admin.Common.Edit").Text,
                    Width = "100",
                    ClassName =  NopColumnClassDefaults.Button,
                    Render = new RenderCustom("renderColumnEdit")
                },
                new ColumnProperty(nameof(VendorAttributeValueModel.Id))
                {
                    Title = T("Admin.Common.Delete").Text,
                    Width = "100",
                    Render = new RenderButtonRemove(T("Admin.Common.Delete").Text),
                    ClassName =  NopColumnClassDefaults.Button
                }
            }
        })
        <script>
            function renderColumnEdit(data, type, row, meta) {
                return '<button onclick=\"javascript:OpenWindow(\'@Url.Content("~/Admin/VendorAttribute/ValueEditPopup/")' + data + '?btnId=btnRefresh&formId=vendorattribute-form\', 800, 400, true); return false;\" class="btn btn-default"><i class="fa fa-pencil"></i>@T("Admin.Common.Edit")</button>';
            }
        </script>
    </div>
    <div class="panel-footer">
        <button type="submit" id="btnAddNewValue" onclick="javascript:OpenWindow('@(Url.Action("ValueCreatePopup", "VendorAttribute", new { vendorAttributeId = Model.Id, btnId = "btnRefresh", formId = "vendorattribute-form" }))', 800, 400, true); return false;" class="btn btn-primary">
            @T("Admin.Vendors.VendorAttributes.Values.AddNew")
        </button>
        <input type="submit" id="btnRefresh" style="display: none" />
        <script>
            $(document).ready(function () {
                $('#btnRefresh').click(function () {
                    //refresh grid
                    updateTable('#vendorattributevalues-grid');

                    //return false to don't reload a page
                    return false;
                });
            });
        </script>
    </div>
}
else
{
    <div class="panel-body">
        @T("Admin.Vendors.VendorAttributes.Values.SaveBeforeEdit")
    </div>
}
